package com.piepesken.mediscale.viewmodels

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.piepesken.mediscale.models.Drug
import com.piepesken.mediscale.repository.DrugRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class DrugViewModel @Inject constructor(
    private val drugRepo: DrugRepository
) : ViewModel() {

    private val _isLoading: MutableLiveData<Boolean> by lazy {
        MutableLiveData<Boolean>(false)
    }

    val drugs: Flow<List<Drug>> by lazy {
        drugRepo.getAllDrugs()
    }

    fun getDrugById(id: Int): Flow<Drug> {
        return drugRepo.getDrugById(id)
    }

    fun filterDrugsByText(text: String): Flow<List<Drug>> {
        return drugRepo.filterDrugsByText(text)
    }

    val isLoading: LiveData<Boolean> get() = _isLoading
}